/*
 * @Author: zxc
 * @Date: 2020-11-25 12:41:11
 * @LastEditTime: 2020-11-25 13:02:29
 * @LastEditors: zxc
 * @Description:有效的括号
 */
/**
 * @param {string} s
 * @return {boolean}
 */
var isValid = function (s) {
  if (s.length % 2 !== 0 || !s) return false
  let map = new Map([
      ["{", "}"],
      ["(", ")"],
      ["[", "]"]
    ]),
    stack = [],
    len = s.length,
    i = 0
  for (; i < len; i++) {
    if (map.has(s[i])) stack.push(s[i])
    else {
      if (map.get(stack[stack.length - 1]) === s[i]) {
        stack.pop()
      } else {
        return false
      }
    }
  }
  return stack.length === 0
}

isValid("()")
